{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0xaa\n",
      "0.123\n",
      "123\n",
      "a\n"
     ]
    }
   ],
   "source": [
    "# define set\n",
    "S = {'0xaa', 123, 'a', 0.123}\n",
    "# S = {2, 1, 1} \n",
    "\n",
    "\n",
    "# determinacy,distinctness and unorderedness\n",
    "for elem in S:\n",
    "    print(elem)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "the cardinality of set S :4\n"
     ]
    }
   ],
   "source": [
    "# calculate cardinality\n",
    "S = {'0xaa', 123, 'a', 0.123}\n",
    "print(f'the cardinality of set :{len(S)}')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\"0xaa\" in S\n"
     ]
    }
   ],
   "source": [
    "# whether the element belongs to the set\n",
    "S = {'0xaa', 123, 'a', 0.123}\n",
    "if \"0xaa\" in S: \n",
    "    print(f'\"0xaa\" in S')\n",
    "else:\n",
    "    print(\"Nope\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The set difference between s1 and s2 is {1, 2, '0xaa'}\n",
      "The set intersection between s1 and s2 is {3, 4}\n",
      "The set union between s1 and s2 is {1, 2, 3, 4, 5, 6, '0xaa', '0xbb'}\n"
     ]
    }
   ],
   "source": [
    "# the operations between sets\n",
    "s1 = {1, 2, 3, 4, \"0xaa\"}\n",
    "s2 = {3, 4 ,5, 6, \"0xbb\"}\n",
    "\n",
    "## Find the set difference\n",
    "print(f'The set difference between s1 and s2 is {s1.difference(s2)}')\n",
    "\n",
    "## Find the set intersection\n",
    "print(f'The set intersection between s1 and s2 is {s1.intersection(s2)}')\n",
    "\n",
    "## Find the set union\n",
    "print(f'The set union between s1 and s2 is {s1.union(s2)}')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0xaa\n",
      "123\n",
      "a\n",
      "0.123\n"
     ]
    }
   ],
   "source": [
    "# Tuples are ordered\n",
    "S = ('0xaa', 123, 'a', 0.123)\n",
    "for i in S:\n",
    "    print(i)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The Cartesian product of s1 and s2 is:\n",
      "(1, '0xbb')\n",
      "(1, 3)\n",
      "(1, 4)\n",
      "(1, 5)\n",
      "(1, 6)\n",
      "(2, '0xbb')\n",
      "(2, 3)\n",
      "(2, 4)\n",
      "(2, 5)\n",
      "(2, 6)\n",
      "(3, '0xbb')\n",
      "(3, 3)\n",
      "(3, 4)\n",
      "(3, 5)\n",
      "(3, 6)\n",
      "(4, '0xbb')\n",
      "(4, 3)\n",
      "(4, 4)\n",
      "(4, 5)\n",
      "(4, 6)\n",
      "('0xaa', '0xbb')\n",
      "('0xaa', 3)\n",
      "('0xaa', 4)\n",
      "('0xaa', 5)\n",
      "('0xaa', 6)\n"
     ]
    }
   ],
   "source": [
    "# Find the Cartesian product\n",
    "import itertools\n",
    "\n",
    "s1 = {1, 2, 3, 4, \"0xaa\"}\n",
    "s2 = {3, 4 ,5, 6, \"0xbb\"}\n",
    "\n",
    "s = itertools.product(s1, s2)\n",
    "print(f'The Cartesian product of s1 and s2 is:')\n",
    "for i in s:\n",
    "    print(i)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "base",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.13"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
